package com.zjbbkj.baibai.device.Controller;

import com.zjbbkj.baibai.common.utils.R;
import com.zjbbkj.baibai.device.service.DeviceService;
import com.zjbbkj.baibai.domain.device.Device;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author WanLi
 * @email wanli_work@163.com
 * @date 2021年08月26日 14:03
 */

@RequestMapping("device/device")
@RestController
public class DeviceController {

    @Resource
    private DeviceService deviceService;


    /** 初始化设备
     * @param IMEIID
     * @return
     */
    @RequestMapping("/insert")
    public R insertDevice(@Valid() @PathVariable("IMEIID") String IMEIID){
        return R.ok().put("device",deviceService.insert(IMEIID));
    }

    @RequestMapping("/update")
    public R updateDevice(@RequestBody Device device){
        return R.ok().put("device",deviceService.update(device));
    }

    /**
     * 根据imeiid获取device
     *
     */
    @RequestMapping("/{IMEIID}")
    public R getDevice(@Valid() @PathVariable("IMEIID") String IMEIID){
        Device device =  deviceService.getDeviceByImeiId(IMEIID);
        return R.ok().put("device",device);
    }






}
